#include "types.h"
#include "param.h"
#include "user.h"
#include "uthread.h" 

int numOfIt;

void
printme(){

	int thId = uthread_self().tid;
	int k = 1;
	while(k <= numOfIt){
		printf(2,"thread %d iteration %d\n",thId,k);
		k++;
		uthread_yield();
	}
}

int
main(int argc, char** argv){
	int i;
	
	if (argc != 3){
		printf(2,"error! not enough arguments\n");
		exit();
	}
	
	int numOfTh = atoi(argv[1]);
	numOfIt = atoi(argv[2]);
	if (numOfIt <= 0){
	    printf(2,"error,number of iteration can't be zero!\n");
	    exit();
	}
		
	for (i = 0; i < numOfTh; i++){
		uthread_create(printme,i);
	}
	
	uthread_start_all();
	exit();
}



